document.getElementById("92").focus()
function getList(){
	$.ajax({
		"url":"/price_admin/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"type":"GET",
		"dataType":"jsonp",
		"success":function(data){
			if(responseCheck(data)){
				for (var i=0;i<data.content.length;i++){
					$("#"+data.content[i].name).val(data.content[i].price)
				}
				//价格历史
				var tab=document.getElementById("tab")
				for (var i=0;i<data.history.length;i++){
					var tr=document.createElement('tr')

					var td=document.createElement('td')
					td.textContent=data.history[i].site
					tr.appendChild(td)

					var td=document.createElement('td')
					td.textContent=data.history[i].oil.toUpperCase()+" #"
					tr.appendChild(td)

					var td=document.createElement('td')
					td.textContent=data.history[i].price
					tr.appendChild(td)

					var td=document.createElement('td')
					td.textContent=data.history[i].date
					tr.appendChild(td)

					tab.appendChild(tr)
				}
			}
		}
	})
}
function setPrice(data,name){
	if(!confirm("请您确认您即将修改 " + name +" 的价格为：\n" + "￥"+ data.price)){
		return false;
	}
	data=JSON.stringify(data)
	$.ajax({
		"url":"/price_admin/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"data":{"data":data},
		"type":"POST",
		"success":function(data){
			if(responseCheck(data)){
				window.location.reload()
			}
		}
	})
}

document.getElementById("92-b").onclick=function(){
	var data={"name":"92"}
	data.price=$("#92").val()
	if (data.price<0){
		showErrorInfo("请填写有效价格！")
		return false;
	}
	setPrice(data,"#92")
}
document.getElementById("95-b").onclick=function(){
	var data={"name":"95"}
	data.price=$("#95").val()
	if (data.price<0){
		showErrorInfo("请填写有效价格！")
		return false;
	}
	setPrice(data,"#95")
}
document.getElementById("98-b").onclick=function(){
	var data={"name":"98"}
	data.price=$("#98").val()
	if (data.price<0){
		showErrorInfo("请填写有效价格！")
		return false;
	}
	setPrice(data,"#98")
}
document.getElementById("0-b").onclick=function(){
	var data={"name":"0"}
	data.price=$("#0").val()
	if (data.price<0){
		showErrorInfo("请填写有效价格！")
		return false;
	}
	setPrice(data,"#0")
}
document.getElementById("lng-b").onclick=function(){
	var data={"name":"lng"}
	data.price=$("#lng").val()
	if (data.price<0){
		showErrorInfo("请填写有效价格！")
		return false;
	}
	setPrice(data,"#LNG")
}
document.getElementById("ele-b").onclick=function(){
	var data={"name":"电"}
	data.price=$("#电").val()
	if (data.price<0){
		showErrorInfo("请填写有效价格！")
		return false;
	}
	setPrice(data,"#电")
}
document.getElementById("92").focus()
getList()
